package com.example.demo.test;

import org.redisson.Redisson;
import org.redisson.api.RBucket;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;

/**
 * RedissonClient 初始化
 */
public class demo6 {

    private static RedissonClient redissonClient;

    public demo6(){
        Config config = new Config();
        config.useSingleServer().setAddress("redis://192.168.0.109:6379");
        config.useSingleServer().setPassword("111111");
        redissonClient = Redisson.create(config);
    }
    // 类加载的时候就可以初始化
    static {
        Config config = new Config();
        config.useSingleServer().setAddress("redis://192.168.0.109:6379");
        config.useSingleServer().setPassword("111111");
        redissonClient = Redisson.create(config);
    }

    // 以上初始化，二选一


    public static void main(String[] args) {
        //demo6 demo6 = new demo6();
        //RBucket<Object> bucket = demo6.redissonClient.getBucket("stock:1");
        //bucket.set("10");

        RBucket<Object> bucket = redissonClient.getBucket("stock:1");
        bucket.set("10");
    }

}
